# ###python正则表达式：
# 1，在一大堆文本字符串中找到自己想要的字符串
# 2，验证输入合不合法
# 正则表达式不是python特有的，而且有自己独立的引擎搜索
# python里面有个re模块，使用正则表达式，是内置模块

# search和match
# match 只匹配字符串的开始 --> 用来匹配字符串的开头

import re
# result = re.search("sanchuang", "this is sanchuang")
# print(result)
# result = re.search("sanchuang", "this is")
# print(result)
# result = re.search("this is sanchuang", "sanchuang")
# print(result)
# print(re.search("\\\ta", "\ta"))
# print("\\\ta")
# # match 只会查找字符串开头
# result = re.match("sanchuang", "this is sanchuang")
# print(result)
# result = re.match("sanchuang", "sanchuangthis is sanchuang")
# print(result)

# import re
# msg = "python ad ad pythondfsd python"
# # 返回列表
# print(re.findall("python", msg))
# # 返回可迭代对象
# print(re.finditer("python", msg))


# --------------------------------------------------
# ###正则表达式
# 区间匹配
# 中括号里任选其一
# 遵循ascill码
# import re
# ret = re.findall("[Pp]y", "pythonPython")
# print(ret)
# ret = re.findall("[a-z]", "adj23ljsdl323232")
# print(ret)
# ret = re.findall("[0-9]", "2fs33sd32354f4")
# print(ret)
# ret = re.findall("a[0-9]b", "a1badfa2ba3ba4b")
# print(ret)
# # 大写字母和小写字母之间还有其他的字符的
# ret = re.findall("[A-z]", "[[[[[")
# print(ret)
# # 匹配数字字母以及下划线
# ret = re.findall("[A-Za-z0-9_]", "jljleALJ-___128")
# print(ret)


# ##取反
# ret = re.findall("[^A-Za-z0-9_]", "jljleALJ-___128")
# print(ret)


# ##或匹配
import re
# msg = "xyf hzj lzw lyl sh"
# print(re.findall("xyf|hzj|sh", msg))
#
# msg = "a3aab45c2"
# print(re.findall("[a-z][0-9]", msg))

# ##'.'占位符 表示除换行符之外的任意一个字符
# import re
# ret = re.findall("p.thon", "python Python pgthon pathon p thon pthon")
# print(ret)


# ##快捷方式
import re
# # \A 匹配字符串的开始
# ret = re.findall(r"\Aworld", "world hello world")
# print(ret)
# ['world']
#
# # \b 词边界 --包含不是字母的时候就是词边界，前后接的不是字母了，就是词边界了
# # 这三个world# 1world！123world
# ret = re.findall(r"world\b", "world# hello aworlda 1world！ 123world")
# print(ret)
#
# # \w 匹配任意单词字符 --》 数字、字母和中文 ———》 跟编码相关
# ret = re.findall(r"\w", "world# hello aworlda 1world！ 123world 两款手机")
# print(ret)
# # \W 匹配任意非单词字符
# ret = re.findall(r"\W", "world# hello aworlda 1world！ 123world")
# print(ret)
#
# # \s 匹配空字符
# ret = re.findall(r"\s", "world# hello aworlda 1world！ 123world")
# print(ret)
# # \S 匹配任意非空字符
# ret = re.findall(r"\S", "world# hello aworlda 1world！ 123world")
# print(ret)
#
# # \d 匹配数字
# ret = re.findall(r"\d", "world# hello aworlda 1world！ 123world")
# print(ret)
# # \D 匹配非数字
# ret = re.findall(r"\D", "world# hello aworlda 1world！ 123world")
# print(ret)


# ##开始与结束
# 匹配以python开头：
# import re
# ret = re.findall("^python", "python pythonsdfsd \npython")
# print(ret)
# # ['python']
#
# # 匹配以python结尾：
# ret = re.findall("python$", "python pythonsdfsd \npython python")
# print(ret)
# # ['python']
# ret = re.findall("python$", "python pythonsdfsd \npython")
# print(ret)
# # ['python']


# ##统配符
# ？ + *
import re
# # ? --> 对这个字符前面的一位匹配0次到一次
# ret = re.findall("py?", "py p python pyython")
# print(ret)
# # ['py', 'p', 'py', 'py']
#
# # + --> 对这个字符前面的一位匹配1次或以上
# ret = re.findall("py+", "py p python pyython")
# print(ret)
# # ['py', 'py', 'pyy']
#
# # * --> 对这个字符前面的一位匹配0次或以上 --》 任意次
# ret = re.findall("py*", "py p python pyython")
# print(ret)
# # ['py', 'p', 'py', 'pyy', 'p']
#
# # 指定匹配n到m次
# ret = re.findall("py{2,4}", "py pyyy pyp yyypy pyy pyyy pyyyyyyyy")
# print(ret)
# # ['pyyy', 'pyy', 'pyyy', 'pyyyy']
# # 最后一个pyyyyyyyy都可以匹配，但是涉及到贪婪匹配，我们都匹配最长的一个
# ret = re.findall("py{2,4}?", "py pyyy pyp yyypy pyy pyyy pyyyyyyyy")
# print(ret)
# # ['pyy', 'pyy', 'pyy', 'pyy']
#
# # 贪婪匹配和非贪婪匹配 --> 默认贪婪模式
# msg = "aba12aaababa"
# ret = re.findall("a.*a", msg)
# print(ret)
#
# msg = "aba12aaababa"
# ret = re.findall("a.*?a", msg)
# print(ret)


# ###
# msg = """
# # tel : 17375722991
# # tel : 173-7572-2991
# # tel : 173 7572 2991
# # tel : (+86)17375722991
# 17375722991123
# """
# ret = re.findall(r"\D(\(\+86\)[0-9]{11})\D|\D(\d{3}[- ]?\d{4}[- ]?\d{4})\D", msg)
# print(ret)
# \D 匹配是不是数字的 ，而( )是为了匹配括号里的，会返回，括号外的是为了筛选，不会返回

#
# # 在字符串中匹配
# msg = "10 100 -100 +100 001 1.1 -1.1 100"
# # 正整数
# ret = re.findall(r"^\+?[0-9]\d+|[ \\+]\d+[0-1]$| \d+ | \+[1-9]\d+", msg)
# print(ret)
# 负整数
# ret = re.findall(r"^\+?[0-9]\d+|\d+[0-1]$| \+?0*\d+ ", msg)
# print(ret)

# 输入匹配
# 正整数
# msg = input("请输入数字：")
# if re.findall(r"^\+?0*\d+$", msg):
#     print(msg, "是正整数")
# else:
#     print(msg, "不是正整数")

# 负整数
# msg = input("请输入数字：")
# if re.findall(r"^-0*\d+$", msg):
#     print(msg, "是负整数")
# else:
#     print(msg, "不是负整数")

# 浮点数
# msg = input("请输入数字：")
# if re.findall(r"^[+-]?0?\d+\.0*\d+$", msg):
#     print(msg, "是浮点数")
# else:
#     print(msg, "不是浮点数")

# ##正则分组

# ret = re.search(r"(\d{3})-(\d){3}-(\d){3}", "abc123-456-789aaa")
# print(ret)
# # 这就是分组
# print(ret.group())
# print(ret.group(1))
# print(ret.group(2))
# print(ret.group(3))
# ret = re.search(r"\d{3}-\d{3}-\d{3}", "abc123-456-789aaa")
# print(ret)
# print(ret.group())

# 捕获分组 --》 (正则表达式)
# 非捕获分组 --》 (?:正则表达式)

# 捕获分组（分组并捕获，分组之后匹配到的数据，会放在内存中，并且给定一个指向）
# msg = "hello sc1 hello1 sc1"
# print(re.search(r"(\w+)\s(\w+)\s\1[1]\s\2", msg))
# <re.Match object; span=(0, 20), match='hello sc1 hello1 sc1'>

# 非捕获分组不会放到内存中
# msg = "a1 a2 a1 a1"
# print(re.search(r"(?:\w+)\s(\w+)\s\1", msg))
# <re.Match object; span=(3, 11), match='a2 a1 a1'>
# 首先我们看“a1 a2 a1”,匹配a1，过，匹a2，过，再匹配a1，发现分组\1是a2，不匹配


# msg = "comyyy@xxx.comcom123@qq.comaaa@126.combbb@163.comcc@abc.com"
# # 123 126 163邮箱
# # com123@qq.com aaa@123.com bbb@163.com
# print(re.findall(r"(?:.com)?(\w+@(?:qq|126|163)\.com)", msg))

# ipv4地址匹配
# msg = input("请输入IPv4地址：")
# print(re.search(r"((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)", msg))


# -------------------------------------------------------------------------------------------
# ##正则分组-分组引用
# import re
# msg = """
# <div>hello<div>
# <hi>hello<hi>
# """
# ret = re.findall(r"(<(\w+)>hello<\2>)", msg)
# print(ret)
# ret = re.search(r"(<(\w+)>hello<\2>)", msg)
# # re.search()只要匹配成功就返回结果
# print(ret.groups())
# print(ret.group(1))
# print(ret.group(2))


# ---------------------------------------------------------------------------------------------
# ##正则标记
# import re
#
# msg = """
# PYTHON
# python
# """
# # re.I参数对里面的正则表达式大小写不敏感
# ret = re.findall(r"python", msg, re.I)
# print(ret)
#
# # 返回为空，以python开头以python结尾就是这一数据只有python这个字符串
# ret = re.findall(r"^python$", msg, re.I)
# print(ret)
# # 这里加入参数re.M进行多行匹配模式，对每一行进行单独的匹配，并返回结果
# ret = re.findall(r"^python$", msg, re.I | re.M)
# print(ret)
#
# msg = """
# zhang shao han
# zhang yi xing
# zhang xue you
# zhang jie
# zhang fei
# xie na
# he jiong
# zhang heng
# """
#
# ret = re.findall(r"^zhang\s[a-z]+$", msg, re.M)
# print(ret)
#
# ret = re.findall(r".+", msg)
# print(ret)
#
# # 可以让占位符' . '除了代表任意字符外还可以代表换行符
# ret = re.findall(r".+", msg, re.S)
# print(ret)


# ------------------------------------------------------------------------
import re
paw = input("请输入密码：")
print(re.findall(r"(^[a-zA-Z](?=.*[a-zA-Z])(?=.*\d))", paw))

# import re
# msg = """
# https://music.163.com/#discover/toplist
# http://www.baidu.com?a=2
# http://sc.cn
# https://new.xin.lang.cn
# http://ww...com
# """
# ret = re.findall(r"https?://(?:\w+\.)+(?:cn|com)", msg)
# print(ret)

# ------------------------------------------------------------------------
# ##正则断言
# import re
# s = "sc1 hello sc2 hello"
# print(re.findall(r"hello(?= sc2)", s))

# msg = """
# 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
#     link/ether 00:0c:29:1b:68:1a brd ff:ff:ff:ff:ff:ff
#     inet 192.168.0.204/24 brd 192.168.0.255 scope global noprefixroute ens33
#        valid_lft forever preferred_lft forever
#     inet6 fe80::20c:29ff:fe1b:681a/64 scope link
#        valid_lft forever preferred_lft forever
# """
# print(re.findall(r"(?<=inet ).*(?=/24)", msg))
